package com.osce.score.controller;

import com.csce.domain.entity.score.ScoreExExamStudent;
import com.osce.common.annotation.Log;
import com.osce.common.core.controller.BaseController;
import com.osce.common.core.entity.AjaxResult;
import com.osce.common.core.page.TableDataInfo;
import com.osce.common.enums.BusinessType;
import com.osce.common.utils.poi.ExcelUtil;
import com.osce.interfaces.score.IScoreExExamStudentService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 考试学员Controller
 *
 * @author zzx
 * @since 2023-09-05
 */
@RestController
@RequestMapping("/score/score_ex_exam_student")
public class ScoreExExamStudentController extends BaseController {

    @Resource
    private IScoreExExamStudentService scoreExExamStudentService;

    /**
     * 查询考试学员列表
     */
    @PreAuthorize("@ss.hasPermi('score:score_ex_exam_student:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScoreExExamStudent scoreExExamStudent) {
        startPage();
        List<ScoreExExamStudent> list = scoreExExamStudentService.selectScoreExExamStudentList(scoreExExamStudent);
        return getDataTable(list);
    }

    /**
     * 查询考试下已添加的考试学员id列表
     */
    @PreAuthorize("@ss.hasPermi('score:score_ex_exam_student:query')")
    @GetMapping("/check-ids/{examId}")
    public TableDataInfo checkIds(@PathVariable("examId") Long examId) {
        List<Long> list = scoreExExamStudentService.selectScoreExExamStudentCheckIds(examId);
        return getDataTable(list);
    }

    /**
     * 导出考试学员列表
     */
    @PreAuthorize("@ss.hasPermi('score:score_ex_exam_student:export')")
    @Log(title = "考试学员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScoreExExamStudent scoreExExamStudent) {
        List<ScoreExExamStudent> list = scoreExExamStudentService.selectScoreExExamStudentList(scoreExExamStudent);
        ExcelUtil<ScoreExExamStudent> util = new ExcelUtil<ScoreExExamStudent>(ScoreExExamStudent.class);
        util.exportExcel(response, list, "考试学员数据");
    }

    /**
     * 获取考试学员详细信息
     */
    @PreAuthorize("@ss.hasPermi('score:score_ex_exam_student:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(scoreExExamStudentService.selectScoreExExamStudentById(id));
    }

    /**
     * 新增考试学员
     */
    @PreAuthorize("@ss.hasPermi('score:score_ex_exam_student:add')")
    @Log(title = "考试学员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScoreExExamStudent scoreExExamStudent) {
        return toAjax(scoreExExamStudentService.insertScoreExExamStudent(scoreExExamStudent));
    }

    /**
     * 批量新增考试学员
     */
    @PreAuthorize("@ss.hasPermi('score:score_ex_exam_student:add')")
    @Log(title = "考试学员", businessType = BusinessType.INSERT)
    @PostMapping("/batch-add")
    public AjaxResult batchAdd(@RequestBody ScoreExExamStudent scoreExExamStudent) {
        return toAjax(scoreExExamStudentService.batchInsertExExamStudent(scoreExExamStudent.getExamId(), scoreExExamStudent.getUserIdList()));
    }

    /**
     * 修改考试学员
     */
    @PreAuthorize("@ss.hasPermi('score:score_ex_exam_student:edit')")
    @Log(title = "考试学员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScoreExExamStudent scoreExExamStudent) {
        return toAjax(scoreExExamStudentService.updateScoreExExamStudent(scoreExExamStudent));
    }

    /**
     * 删除考试学员
     */
    @PreAuthorize("@ss.hasPermi('score:score_ex_exam_student:remove')")
    @Log(title = "考试学员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(scoreExExamStudentService.deleteScoreExExamStudentByIds(ids));
    }

    /**
     * 根据考试编号和学员编号集合批量删除考试学员
     */
    @PreAuthorize("@ss.hasPermi('score:score_ex_exam_student:remove')")
    @Log(title = "考试学员", businessType = BusinessType.DELETE)
    @DeleteMapping("/batch-remove-by-examId")
    public AjaxResult batchRemove(@RequestBody ScoreExExamStudent scoreExExamStudent) {
        return toAjax(scoreExExamStudentService.batchDeleteScoreExExamStudentByIds(scoreExExamStudent));
    }
}
